package zmee.bid.report;

import kd.bos.context.RequestContext;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.report.FilterInfo;
import kd.bos.entity.report.ReportQueryParam;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.report.plugin.AbstractReportFormPlugin;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.taxc.tccit.formplugin.account.BusinessEntertainmentCostTZFormPlugin;
import zmee.util.DateUtil;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* @author lijiawang
* @Date 2023/1/30 14:43
* @Description:公司项目报表
*/
public class OrgProjectrpttplReport extends AbstractReportFormPlugin {
    //单元格相同的合并
    @Override
    public void setMergeColums(List<String> columns) {
       super.setMergeColums(columns);
        columns.add("org");
    }

    //查询条件默认值设置
    @Override
    public void initDefaultQueryParam(ReportQueryParam queryParam) {
        Object[] org=new Object[]{RequestContext.get().getOrgId()};
        this.getModel().setValue("bosorg", org);
    }

    @Override
    public void processRowData(String gridPK, DynamicObjectCollection rowData, ReportQueryParam queryParam) {
        for (DynamicObject row:rowData) {
            BigDecimal totalpay = row.getBigDecimal("totalpay");
            BigDecimal yearpay = row.getBigDecimal("yearpay");
            BigDecimal budge = row.getBigDecimal("budgetamt");
            BigDecimal yearbudget = row.getBigDecimal("yearbudget");
            BigDecimal divide=new BigDecimal("0.00");
            BigDecimal budget=new BigDecimal("0.00");
            try {
                divide = totalpay.divide(budge, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")).setScale(2, BigDecimal.ROUND_HALF_UP);
                budget= yearpay.divide(yearbudget,4,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")).setScale(2,BigDecimal.ROUND_HALF_UP);
            }catch (Exception e){
                e.printStackTrace();
            }

            //预算完成率
            row.set("totalbudgetfinish",divide.toString()+"%");
            row.set("yearbudgetfinish",budget.toString()+"%");
        }
    }

}
